package com.zuqiuzhandui.liveing.view.choose;

import android.view.View;
import android.widget.TextView;

import com.code19.library.DateUtils;
import com.zuqiuzhandui.R;
import com.zuqiuzhandui.liveing.model.enumModel.ScheduleEnum;
import com.zuqiuzhandui.liveing.model.resultModel.TeamScheduleRs;
import com.zuqiuzhandui.liveing.util.DateUtil;

import butterknife.ButterKnife;

/**
 * Created by yq on 2016-10-13.
 */

public class ScheduleItem {
    static final String format_2 = "HH:mm";
    static final String format = "MM-dd";
    static final String[] week = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};

    public static void setItemView(TeamScheduleRs data, View view) {
        view.setVisibility(View.VISIBLE);
        TextView tvDate = ButterKnife.findById(view, R.id.tv_date);
        TextView tvTime = ButterKnife.findById(view, R.id.tv_time);
        TextView tvTitle = ButterKnife.findById(view, R.id.tv_title);
        TextView tvTurn = ButterKnife.findById(view, R.id.tv_turn);
        TextView tvTeamA = ButterKnife.findById(view, R.id.tv_team_a);
        TextView tvTeamB = ButterKnife.findById(view, R.id.tv_team_b);
        TextView tvVs=ButterKnife.findById(view,R.id.tv_vs);

        if (data==null)
        {
            tvDate.setText("");
            tvTime.setText("");
            tvTitle.setText("");
            tvTurn.setText("");
            tvTeamA.setText("");
            tvTeamB.setText("");
            tvVs.setVisibility(View.INVISIBLE);
            return;
        }
        String date = DateUtils.formatDateCustom(data.getActionTime(), format);
        data.setActionTime(data.getActionTime());
        int weekIndex = DateUtil.getWeek("" + data.getActionTime());
        tvDate.setText(date+" "+week[weekIndex-1]);
        tvTime.setText(DateUtils.formatDateCustom(data.getActionTime(),format_2));
        if (data.getScheduleType().equals(ScheduleEnum.TRAINING.toString())){
            //对内训练
            tvTurn.setVisibility(View.INVISIBLE);
            tvTeamA.setVisibility(View.INVISIBLE);
            tvTeamB.setVisibility(View.INVISIBLE);
            tvVs.setVisibility(View.INVISIBLE);
            tvTitle.setText(R.string.team_train);
        }
        else if (data.getScheduleType().equals(ScheduleEnum.MATCH.toString()))
        {
            //训练赛
            tvTurn.setVisibility(View.INVISIBLE);
            tvTeamA.setVisibility(View.VISIBLE);
            tvTeamB.setVisibility(View.VISIBLE);
            tvVs.setVisibility(View.VISIBLE);
            tvTitle.setText(R.string.friendly);
            tvTeamA.setText(data.getTeams().get(0).getName());
            tvTeamB.setText(data.getTeams().get(1).getName());
        }
        else if (data.getScheduleType().equals(ScheduleEnum.LEAGUE.toString()))
        {
            tvTurn.setVisibility(View.VISIBLE);
            tvTeamA.setVisibility(View.VISIBLE);
            tvTeamB.setVisibility(View.VISIBLE);
            tvVs.setVisibility(View.VISIBLE);
            tvTitle.setText(data.getTitle());
            tvTeamA.setText(data.getTeams().get(0).getName());
            tvTeamB.setText(data.getTeams().get(1).getName());

            tvTurn.setText("第"+data.getMatch_round()+"轮");
        }

    }
}
